// 调用cordova中的代码实现原生应用中的功能

// const inCordova = 

import {
  AlertModule
} from 'vux';

const bridge = {
  // 调起王者荣耀
  callHonorOfKings: function () {
    // alert(typeof appAvailability);

    let successCb = function(data) {
      alert('successCb')
    }

    let failCb = function(err) {
      alert('error' + err)
    }

    alert(typeof window.plugins)
    if(window.plugins) {
      if(window.plugins.launcher) {
        window.plugins.launcher.canLaunch({packageName:'com.tencent.tmgp.sgame'}, successCb, failCb);
      }
    }

    if (appAvailability) {
      // 需要打开的应用包名
      let scheme = "com.tencent.tmgp.sgame";
      appAvailability.check(scheme,
        // 成功之后的回调 
        function () {
          alert('已安装王者荣耀');
          let sApp = startApp.set({
            "action": "ACTION_MAIN",
            "category": "CATEGORY_DEFAULT",
            "type": "text/css",
            "package": scheme,
            "uri": "file://data/index.html",
            "flags": ["FLAG_ACTIVITY_CLEAR_TOP", "FLAG_ACTIVITY_CLEAR_TASK"],
            "instentstart": "startActivity"
          }, {
            "EXTRA_STREAM": "fromStrategy"
          });

          sApp.start(function ( /* 打开成功 */ ) {
            alert('App打开成功');
          }, function ( /* 打开失败 */ ) {
            alert('程序打开失败');
          })
        },
        // 失败之后的回调
        function () {
          alert('请先安装王者荣耀！');
        })
    }
  }
}


export default bridge;
